package com.shuzijun.leetcode.editor.cn;

import java.util.Stack;

public class ValidParentheses{
    public static void main(String[] args) {
         Solution solution = new ValidParentheses().new Solution();
         solution.isValid("()");
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == '(' || c == '[' || c =='{'){
                stack.push(c);
            } else {
                if (stack.empty()) return false;

                Character popC = stack.pop();
                if (c == ')' && popC != '('){
                    return false;
                }

                if (c == '}' && popC != '{'){
                    return false;
                }
            }
        }
        return stack.empty();
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}